package factory.absfactory.pizzastore.order;

import factory.factorymethod.pizzastore.pizz.Pizz;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @Author liangliangzhao
 * @data 2023/2/28 14:44
 */

public class OrderPizza {
    AbsFactory absFactory;

    public OrderPizza(AbsFactory absFactory){
        setAbsFactory(absFactory);
    }

    public void setAbsFactory(AbsFactory absFactory){
        Pizz pizz = null;
        String orderType = "";//用户输入
        do{
            orderType = getType();
            pizz = absFactory.createPizza(orderType);
            if(pizz != null){
                pizz.prepare();
                pizz.bake();
                pizz.cut();
                pizz.bake();
            }else {
                System.out.println("订购失败");
                break;
            }
        }while (true);
    }

    private String getType(){
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza 种类");
            String str = strin.readLine();
            return str;
        }catch (IOException e){
            e.printStackTrace();
            return "";
        }
    }
}
